package com.kunpeng.weibo.weixin.api;

import android.graphics.Bitmap;

import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.SendMessageToWX;
import com.tencent.mm.sdk.openapi.WXMediaMessage;
import com.tencent.mm.sdk.openapi.WXMusicObject;
import com.tencent.mm.sdk.platformtools.Util;

public class SendAudio_API extends Request_API {

	public SendAudio_API(IWXAPI api) {
		super(api);
	}

	/**
	 * 分享音频
	 * 
	 * @param url
	 * @param title 标题
	 * @param desc 描述
	 * @param thumb 缩略图
	 */
	public void sendAudioWithUrl(String url, String title, String desc, Bitmap thumb) throws IllegalArgumentException {
		if (url == null || url.equals("") || !url.startsWith("http")) {
			throw new IllegalArgumentException();
		}
		WXMusicObject music = new WXMusicObject();
		music.musicUrl = url;

		WXMediaMessage msg = new WXMediaMessage();
		msg.mediaObject = music;
		if (title != null) {
			msg.title = title;
		}
		if (desc != null) {
			msg.description = desc;
		}
		if (thumb != null) {
			msg.thumbData = Util.bmpToByteArray(thumb, true);
		}
		SendMessageToWX.Req req = new SendMessageToWX.Req();
		req.transaction = buildTransaction("music");
		req.message = msg;
		mWeixinApi.sendReq(req);
	}

	/**
	 * 分享低带宽音频
	 * 
	 * @param url
	 * @param title
	 * @param desc
	 * @param thumb
	 * @throws IllegalArgumentException
	 */
	public void sendAudioWithLowBandUrl(String url, String title, String desc, Bitmap thumb) throws IllegalArgumentException {
		if (url == null || url.equals("") || !url.startsWith("http")) {
			throw new IllegalArgumentException();
		}
		WXMusicObject music = new WXMusicObject();
		music.musicLowBandUrl = url;

		WXMediaMessage msg = new WXMediaMessage();
		msg.mediaObject = music;
		if (title != null) {
			msg.title = title;
		}
		if (desc != null) {
			msg.description = desc;
		}
		if (thumb != null) {
			msg.thumbData = Util.bmpToByteArray(thumb, true);
		}
		SendMessageToWX.Req req = new SendMessageToWX.Req();
		req.transaction = buildTransaction("music");
		req.message = msg;
		mWeixinApi.sendReq(req);
	}

}
